<template>
  <div id="app">
    <router-view/>
    <div v-if="isLoading" style="background:#fff;position: fixed;top:0;left:0;bottom:0;right:0">
      <lottie :options="defaultOptions" :width="200" v-on:animCreated="handleAnimation"/>
    </div>
    <Tabbar v-if="showFooter"></Tabbar>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import {getWxAuth} from '@/api/wxlogin'
import lottie from 'vue-lottie'
import Tabbar from './components/Tabbar'
import * as animationData from '@/assets/books.json'

export default {
  name: 'App',
  data () {
    return {
      defaultOptions: {animationData: animationData},
      animationSpeed: 1,
      anim: {}
    }
  },
  created () {
    //      if (!getQueryString('token')) {
    //        console.log('授权登录')
    //        this.returnGetCodeUrl()
    //      } else {
    //        console.log('登录成功')
    //        const msg = getQueryString('msg')
    //        if ((Number(msg) === 200)) {
    //          const token = getQueryString('token')
    //          console.log(getUserInfo({
    //            token :token
    //          }))
    //          this.$router.push({
    //            path: '/'
    //          })
    //        } else {
    //          alert('授权失败请关闭网页重新进入')
    //        }
    //      }
  },
  methods: {
    async returnGetCodeUrl () {
      console.log('11111')
      debugger
      let {data} = await getWxAuth({})
      console.log(data)
      debugger
      if (data.status === 200) {
        window.location.href = data.url
      }
    },
    handleAnimation: function (anim) {
      this.anim = anim
    }
  },
  computed: {
    ...mapState({
      isLoading: state => state.isLoading,
      showFooter: state => state.showFooter
    })
  },
  watch: {
    $route (to, from) {
      if (to.name === 'Mine' || to.name === 'Seat' || to.name === 'Order') {
        this.$store.dispatch('showFooter', {showFooter: true})
      } else {
        this.$store.dispatch('showFooter', {showFooter: false})
      }
    }
  },
  components: {
    Tabbar,
    lottie
  }
}
</script>

<style>
.weui-tabbar {
  position: fixed !important;
  z-index: 10 !important;
}

.vux-loading .weui-toast {
  top: 50% !important;
  transform: translateX(-50%) translateY(-50%) !important;
  width: 150px !important;
}
</style>
